package com.zeng.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

@Service("emailUtils")
public class EmailUtils {

    @Autowired
    JavaMailSenderImpl mailSender;

    @Value("${spring.mail.username}")
    private String mail;

    public void send(String usermail, String vicode) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setSubject("校园交易商城邮箱验证");
        mailMessage.setText("您正在校园交易市场进行邮箱绑定的操作，本次请求的邮件验证码是：" + vicode + "(为了保证您账号的安全性，请您在5分钟内完成验证).\n" +
                "本验证码5分钟内有效，请及时输入。\n" +
                "为保证账号安全，请勿泄漏此验证码。\n" +
                "祝在【校园交易市场】收获愉快！\n" +
                "（这是一封自动发送的邮件，请不要直接回复）");
        mailMessage.setTo(usermail);
        mailMessage.setFrom(mail);
        mailSender.send(mailMessage);
    }
}